package module.service.impl;

import common.bean.SearchPageResult;
import common.bean.SearchParameter;
import module.dao.AssessmentGradingDao;
import module.model.AssessmentDataModel;
import module.model.AssessmentGradingModel;
import module.service.AssessmentGradingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 评估分级
 */
@Service
public class AssessmentGradingServiceImpl implements AssessmentGradingService {
    @Autowired
    private AssessmentGradingDao assessmentGradingDao;
    @Transactional
    public List<AssessmentGradingModel> getAssessmentGradingModelListBySearchParameter(SearchParameter searchParameter) {
        return assessmentGradingDao.getAssessmentGradingModelListBySearchParameter(searchParameter);
    }

    @Transactional
    public List<AssessmentGradingModel> getAssessmentGradingModelList(Integer gradingType, Long objId) {
        SearchParameter searchParameter = new SearchParameter();
        searchParameter.addParam("gradingType",gradingType);
        searchParameter.addParam("objId",objId);
        return getAssessmentGradingModelListBySearchParameter(searchParameter);
    }

    @Transactional
    public AssessmentGradingModel saveAssessmentGradingModel(AssessmentGradingModel assessmentGradingModel) {
        if(assessmentGradingModel.getGradingId()==null){
            assessmentGradingModel.setCreateDate(new Date());
            assessmentGradingDao.save(assessmentGradingModel);
        }else{
            assessmentGradingDao.update(assessmentGradingModel);
        }
        return assessmentGradingModel;
    }
    @Transactional
    public void deleteAssessmentGradingModelById(Long gradingId) {
        assessmentGradingDao.deleteById(AssessmentGradingModel.class,gradingId);
    }
    @Transactional
    public SearchPageResult<AssessmentGradingModel> getAssessmentGradingModelListPage(SearchParameter searchParameter) {
        return assessmentGradingDao.getAssessmentGradingModelListPage(searchParameter);
    }
    @Transactional
    public AssessmentGradingModel getAssessmentGradingModelByGradingId(Long gradingId){
        return assessmentGradingDao.load(AssessmentGradingModel.class,gradingId);
    }
}
